<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->

<mat-card appearance="outlined" class="card">
  <div class="card__header">
    <img class="card__header__logo" src="/assets/gravitee-logo-dark-blue.png" alt="Gravitee.io" />
    <div class="card__header__title">Sign In</div>
    <div class="card__header__subtitle">to continue to the APIM Console</div>
  </div>

  <form *ngIf="!localLoginDisabled" class="card__form" [formGroup]="loginForm" (ngSubmit)="login()">
    <mat-form-field class="card__form__input">
      <mat-label>Username</mat-label>
      <input matInput type="text" formControlName="username" autofocus data-testid="username-input" />
      <mat-error *ngIf="loginForm.get('username').hasError('required')">Username is required.</mat-error>
    </mat-form-field>

    <mat-form-field class="card__form__input">
      <mat-label>Password</mat-label>
      <input matInput type="password" formControlName="password" data-testid="password-input" />
      <mat-error *ngIf="loginForm.get('password').hasError('required')">Password is required.</mat-error>
    </mat-form-field>

    <button
      type="submit"
      class="card__form__button"
      mat-raised-button
      [disabled]="loginForm.invalid || loginInProgress"
      data-testid="sign-in-button"
    >
      <mat-icon svgIcon="gio:login"></mat-icon>
      Sign in
    </button>

    <p class="card__form__goTo" *ngIf="userCreationEnabled">Don't have an account yet? <a routerLink="/_sign-up">Sign up</a></p>
  </form>

  <div class="card__providers">
    <button
      *ngFor="let provider of identityProviders"
      (click)="authenticate(provider)"
      class="card__providers__button"
      [ngClass]="'card__providers__button--' + (provider.type | lowercase)"
      [ngStyle]="{ 'background-color': provider.color }"
      mat-raised-button
    >
      <span class="card__providers__button__wrapper">
        <mat-icon class="card__providers__button__wrapper__logo" [svgIcon]="'idp-' + provider.type | lowercase"></mat-icon>
        <span class="card__providers__button__wrapper__name">{{ provider.name }}</span>
      </span>
    </button>
  </div>
</mat-card>
